var S$ = jQuery.noConflict();
S$(document).ready(function() {

  if (S$.browser.msie && S$.browser.version < 7) return; // Don't execute code if it's IE6 or below cause it doesn't support it.
  
    S$(".fade").fadeTo(1, 1);
    S$(".fade").hover(
      function () {
        S$(this).fadeTo("fast", 0.6);
      },
      function () {
        S$(this).fadeTo("slow", 1);
      }
  ); 
  
  
  ddsmoothmenu.init({
  	mainmenuid: "smoothmenu1", //menu DIV id
  	orientation: 'h', //Horizontal or vertical menu: Set to "h" or "v"
  	classname: 'ddsmoothmenu', //class added to menu's outer DIV
  	//customtheme: ["#1c5a80", "#18374a"],
  	contentsource: "markup" //"markup" or ["container_id", "path_to_menu_file"]
  })
  
  S$('.ddsmoothmenu ul li a.selected').hover(function() { //mouse in
		S$(this).css({'color':'#ffffff'});
    Cufon.refresh();
	}, function() { //mouse out
		S$(this).css({'backgroundColor':'#72a200','color':'#ffffff'});
	});
      
  S$(".tabs_container").each(function(){
  	S$("ul.tabs",this).tabs("div.panes > div", {tabs:'li',effect: 'fade', fadeOutSpeed: -400});
  });
  S$(".mini_tabs_container").each(function(){
  	S$("ul.mini_tabs",this).tabs("div.panes > div", {tabs:'li',effect: 'fade', fadeOutSpeed: -400});
  });
  S$.tools.tabs.addEffect("slide", function(i, done) {
  	this.getPanes().slideUp();
  	this.getPanes().eq(i).slideDown(function()  {
  		done.call();
  	});
  });
  
  S$('.toggle .toggle_content:first').show();
	S$(".toggle_title").toggle(
		function(){
			S$(this).addClass('toggle_active');
			S$(this).siblings('.toggle_content').slideDown("fast");
		},
		function(){
			S$(this).removeClass('toggle_active');
			S$(this).siblings('.toggle_content').slideUp("fast");
		}
	);
  	
  /* initialize prettyphoto */
  S$("a[rel^='prettyPhoto']").prettyPhoto({
  	theme: 'light_square'
  });

S$('#buttonsend').click( function() {
	
		var name    = S$('#contactname').val();
		var subject = S$('#contactsubject').val();
		var email   = S$('#contactemail').val();
		var message = S$('#contactmessage').val();
		
		S$('.loading').fadeIn('fast');
		
		if (name != "" && subject != "" && email != "" && message != "")
			{

				S$.ajax(
					{
						url: './sendemail.php',
						type: 'POST',
						data: "name=" + name + "&subject=" + subject + "&email=" + email + "&message=" + message,
						success: function(result) 
						{
							S$('.loading').fadeOut('fast');
							if(result == "email_error") {
								S$('#contactemail').css("border","1px solid #FFB8B8").next('.require').text(' !');
							} else {
								S$('#contactname, #contactsubject, #contactemail, #contactmessage').css("border","1px solid #eaeaea").val("");
								S$('<div class="success-message">Your message has been sent successfully. Thank you! </div>').insertBefore('#maincontactform');
								S$('.success-message').fadeOut(6000, function(){ S$(this).remove(); });
							}
						}
					}
				);
				return false;
				
			} 
		else 
			{
				S$('.loading').fadeOut('fast');
				if(name == "") S$('#contactname').css("border","1px solid #FFB8B8").next('.require').text(' !');
				if(subject == "") S$('#contactsubject').css("border","1px solid #FFB8B8").next('.require').text(' !');
				if(email == "" ) S$('#contactemail').css("border","1px solid #FFB8B8").next('.require').text(' !');
				if(message == "") S$('#contactmessage').css("border","1px solid #FFB8B8").next('.require').text(' !');
				return false;
			}
	});
	
	S$('#contactname, #contactsubject, #contactemail,#contactmessage').focus(function(){
		S$(this).css({"border":"1px solid #eaeaea"}).next('.require').text(' *');
	});
        
});